"""
@Filename       : meme_preprocess.py
@Create Time    : 2021/3/17 14:51
@Author         : Rylynn
@Description    : 

"""
import os


def load_graph(rootpath, file, keep_user):
    filepath = os.path.join(rootpath, file)
    graph_file = open(os.path.join(rootpath, 'processed', 'graph.txt'), mode='w+', encoding='utf8')

    with open(filepath, 'r+') as f:
        for line in f.readlines():
            mutual, time, source, target = line.split(',')
            mutual = eval(mutual)
            source = eval(source)
            target = eval(target)
            if source not in keep_user or target not in keep_user:
                continue
            if mutual == 1:
                graph_file.write('{} {}\n'.format(source, target))
                graph_file.write('{} {}\n'.format(target, source))
            else:
                graph_file.write('{} {}\n'.format(source, target))


def load_diffusion_data(rootpath, file):
    filepath = os.path.join(rootpath, file)
    user_freq_dict = {}
    with open(filepath, 'r', encoding='utf8') as f:
        print(f.readline())


if __name__ == '__main__':
    load_diffusion_data('F:/data/diffusion/memes', 'quotes_2009-04.txt',)
    # load_graph('F:/data/diffusion/digg', 'digg_friends.csv', keep_user)
